import { Component } from 'react'
import TodoItem from './TodoItem'

class TodoList extends Component {
  constructor(props) {
    super(props);
    this.state = {
      list: [],
      inputValue: ''
    }
    // this.handleChangeInput = this.handleChangeInput.bind(this)
    // this.handleClick = this.handleClick.bind(this)
    // this.getList = this.getList.bind(this)
  }
  render() {
    return (
      <div>
        <input value={this.state.inputValue} onChange={this.handleChangeInput} />
        <button onClick={this.handleClick}>确定</button>
        <TodoItem list={this.state.list} del={this.handleDel}></TodoItem>
      </div>
    )
  }



  handleChangeInput = (e) => {
    this.setState({
      inputValue: e.target.value
    })
  }

  handleDel = (index) => {
    const list = [...this.state.list]
    list.splice(index, 1)
    this.setState({
      list,
    })
  }
  handleClick = () => {
    const list = [...this.state.list, this.state.inputValue]
    this.setState({
      list,
      inputValue: ''
    })
  }
}

export default TodoList
